{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3caac6f-1204-488b-b99c-c5f5ed75768f",
   "metadata": {},
   "outputs": [],
   "source": [
    "###  Python中可以使用数字代替True和False ###\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "fd1d0810-22eb-48a7-8d3f-b3bcc088c640",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n",
      "如果当条件为真时，这条语句就会在控制台中输出...\n"
     ]
    }
   ],
   "source": [
    "# 使用数字描述布尔型数据\n",
    "# coding:UTF-8\n",
    "flag_result = 11     # 此处是非0数值所以它为True\n",
    "print(type(flag_result))\n",
    "if flag_result:      # \n",
    "    print('如果当条件为真时，这条语句就会在控制台中输出...')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bb16927b-fdfa-44d1-b1c7-935347b59ef5",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'int_result' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[4], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m bool_val_f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m     \u001b[38;5;66;03m# 定义一个布尔类型的变量\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m bool_sum_test \u001b[38;5;241m=\u001b[39m int_result \u001b[38;5;241m+\u001b[39m bool_val_f  \u001b[38;5;66;03m# 把整型变量与布尔类型变量相加\u001b[39;00m\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28mprint\u001b[39m(bool_sum_test)\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mtype\u001b[39m(bool_sum_test))\n",
      "\u001b[1;31mNameError\u001b[0m: name 'int_result' is not defined"
     ]
    }
   ],
   "source": [
    "bool_val_f = False     # 定义一个布尔类型的变量\n",
    "bool_sum_test = int_result + bool_val_f  # 把整型变量与布尔类型变量相加\n",
    "print(bool_sum_test)\n",
    "print(type(bool_sum_test))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98af1fca-3ed8-4bc5-8182-09f58c4d2a5e",
   "metadata": {},
   "source": [
    "input()函数使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e0502d46-5ede-4c2d-966a-eebcb0662583",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入第一个数字： 3455.66\n",
      "请输入第二个数字： 456.88\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3455.66+456.88=3912.54\n"
     ]
    }
   ],
   "source": [
    "# 将键盘输入的数据直接利用float()函数转换为浮点数\n",
    "num_a = float(input('请输入第一个数字：'))\n",
    "num_b = float(input('请输入第二个数字：'))\n",
    "result = num_a + num_b   # 将两个数字的和\n",
    "# 非字符串数据使用\"+\"与字符串连接时，必须使用str()将其转换成字符串，否则报错\n",
    "print(str(num_a) + \"+\" + str(num_b) + \"=\" + str(result))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "012fd95e-aee0-4f66-af81-17af9333a85a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我今年18岁了，我在\"www.baidu.com\"进行上网网购，预计花费：8.170000E+02\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出\n",
    "age = 18\n",
    "url = 'www.baidu.com'\n",
    "pay = 817\n",
    "# %d d指的是decimal,表示整数\n",
    "# %s s指的是string,表示字符串\n",
    "print('我今年%d岁了，我在\"%s\"进行上网网购，预计花费：%E' % (age, url, pay))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b59c05d9-74d8-4636-b470-b82bb723ae99",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：老许， 年龄：20， 成绩： 97.80\n"
     ]
    }
   ],
   "source": [
    "name = '老许'\n",
    "age = 20\n",
    "score = 97.8\n",
    "# 6.2f表示 小数点前保留6位数 小数点后保留2位数\n",
    "print(\"姓名：%(name)s， 年龄：%(age)d， 成绩：%(score)6.2f\" % vars())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd96ce1a-c63d-4a8c-beaf-9ffbf4529830",
   "metadata": {},
   "source": [
    "### 字符串的判断操作 \n",
    "- isalnum()\n",
    "- isnumeric()\n",
    "- isalpha()\n",
    "- isprintable()\n",
    "- isascii()\n",
    "- isspace()\n",
    "- isdecimal()\n",
    "- istitle()\n",
    "- isdigit()\n",
    "- isupper()\n",
    "- isdentifier()\n",
    "- islower()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bce70efb-ddb1-43eb-ae1a-d5e33d9d3af9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "python123\n"
     ]
    }
   ],
   "source": [
    "strs_re = 'python123'  # 字母加数字的一种组合 是否符合\n",
    "str_isalnum = strs_re.isalnum()\n",
    "print(strs_re)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1373b431-e155-4371-8958-c042aca45886",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "str_isnumeric = strs_re.isnumeric() # 是否是纯数字\n",
    "print(str_isnumeric)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d8706f71-513a-40b5-bdca-21d9ba0b2844",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "str_isalpha = strs_re.isalpha() # 是否都是字母\n",
    "print(str_isalpha)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e77ee8fc-3def-4348-9da8-c84108592cde",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "str_isprintable = strs_re.isprintable() # 是否是组合的操作\n",
    "print(str_isprintable)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af6f10ea-5304-4a3a-bbf6-a74af4561111",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
